/**
 * 
 */
package com.terrence.filemgr.mgr.impl.ftp;

import java.util.Properties;

import org.apache.commons.lang.StringUtils;

import com.terrence.filemgr.mgr.AbsFileMgrContext;

/**
 * @author wuchuang
 *
 * 2016年11月10日 下午2:49:45
 * 
 * FTP上下文信息
 */
public class FTPContext extends AbsFileMgrContext {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9220380180747280913L;
	
	private final static String DEFAULT_BASE_DIR = "/fileMgr";
	
	//FTP服务器
	private String hostName;
	//FTP端口(默认为21)
	private int port;
	//用户名
	private String userName;
	//密码
	private String password;
	//基础目录(默认为/fileMgr目录)
	private String baseDir = DEFAULT_BASE_DIR;
	//数据传输模式(默认为被动)
	private Boolean isPasv;
	
	public FTPContext() {
		super();
	}
	
	public static FTPContext getInstance(Properties properties){
		FTPContext context = new FTPContext();
		context.setHostName(properties.getProperty("ftp.hostname",""));
		context.setPort(Integer.valueOf(properties.getProperty("ftp.port","21")));
		context.setUserName(properties.getProperty("ftp.username",""));
		context.setPassword(properties.getProperty("ftp.password",""));
		context.setBaseDir(properties.getProperty("ftp.baseDir", DEFAULT_BASE_DIR));
		context.setIsUnix(StringUtils.equalsIgnoreCase("true",properties.getProperty("ftp.isUnix", "true")));
		context.setIsPasv(StringUtils.equalsIgnoreCase("true",properties.getProperty("ftp.isPasv", "true")));
		context.setEncoding(properties.getProperty("ftp.encoding", "UTF-8"));
		return context;
	}

	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getBaseDir() {
		return baseDir;
	}

	public void setBaseDir(String baseDir) {
		this.baseDir = baseDir;
	}

	public Boolean getIsPasv() {
		return isPasv;
	}

	public void setIsPasv(Boolean isPasv) {
		this.isPasv = isPasv;
	}
		
}
